package com.sunyur.tailor.channel.service.outer.user.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sunyur.tailor.channel.common.middle.base.ChannelListResult;
import com.sunyur.tailor.channel.common.middle.enums.MiddleResultEnum;
import com.sunyur.tailor.channel.common.middle.util.ChannelListResultUtil;
import com.sunyur.tailor.channel.common.middle.util.RestTemplateUtil;
import com.sunyur.tailor.channel.service.outer.user.model.OuterUserModel;
import com.sunyur.tailor.channel.service.outer.user.param.OuterUserParam;
import com.sunyur.tailor.channel.service.outer.user.service.OuterUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Objects;

/**
 *
 * @Author 99288
 * @Description 外部人员实现类
 * @Date 22:37 2021/7/7
 * @Param
 * @return
**/
@Slf4j
@Service("outerUserService")
public class OuterUserServiceImpl implements OuterUserService {

    @Value("${outer.oa.user}")
    private String userUrl;

    @Autowired
    private RestTemplateUtil<OuterUserParam> restTemplateUtil;

    @Override
    public ChannelListResult<OuterUserModel> getUserList(OuterUserParam outerUserParam) {
        log.error("get outer user param:{}", JSON.toJSONString(outerUserParam));
        if (Objects.isNull(outerUserParam)) {
            return ChannelListResultUtil.error(MiddleResultEnum.PARAM_NULL.getCode(), MiddleResultEnum.PARAM_NULL.getValue());
        }
        // 查询接口
        JSONObject jsonObject = restTemplateUtil.exchangeFormUrlencodedPost(outerUserParam, userUrl);
        if (Objects.nonNull(jsonObject)) {

        }
        return ChannelListResultUtil.error(MiddleResultEnum.FAILED.getCode(), MiddleResultEnum.FAILED.getValue());
    }
}